package com.xxwy.bean.definition;

import com.xxwy.bean.DefaultUserFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 外部对象如何注入
 * @author wy
 * @date 2020/4/21 17:06
 */
public class SingleToBeanRegistrationDemo {

  public static void main(String[] args) {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.register(SingleToBeanRegistrationDemo.class);
    applicationContext.refresh();

    DefaultUserFactory factory = new DefaultUserFactory();
    ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    beanFactory.registerSingleton("factory",factory);

    Object bean = applicationContext.getBean("factory");

    //true
    System.out.println(factory == bean);
    applicationContext.close();
  }
}
